#include "login.h"

//判断是否能够正确登录       
//返回值-1不能登录，0登陆成功
int judge_login(int netFD){

     while(1){
     printf("请输入以下数字进行选择：\n");
     printf("1、登录   2、注册  3、注销\n");
     char buf[5] = { 0 };
     int ret = read(STDIN_FILENO, buf, sizeof(buf));
     ERROR_CHECK(ret, -1, "read_main.c");
     if(strlen(buf) > 2){
         printf("输入数据错误\n");
         return -1;
     }
     //把换行符给去掉
     buf[1] = '\0';
     int num = atoi(buf);
     send(netFD, &num, sizeof(num), MSG_NOSIGNAL);
     int res;
     switch(num){
     case 1:
         res = jg_login(netFD);
         break;
     case 2:
         res = jg_register(netFD);
         break;
     case 3:
         res = cancel(netFD);
         break;
     default:
         return -1;
     }
     if(res == 0){
         return 0;
     }
 }
     return -1;
}
